package reflect;

import reflect.annotation.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectDemo8 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class cls=Class.forName("reflect.Person");
        Object o = cls.newInstance();
        Method method= cls.getMethod("sleep");
        if (method.isAnnotationPresent(AutoRunMethod.class)){
            AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
            System.out.println("参数="+arm.value());
            method.invoke(o);

        }
    }
}
